<!-- 病历信息 -->
<template>
  <div class="mod-config">
    <basic-container>
      <div class="avue-crud">
        <el-divider content-position="center" v-if="list.length">顾客验光记录</el-divider>
        <table class="miui-table" v-for="item in list" :key="item.id">
          <tr class="miui-table-header">
            <td colspan="5">验光号：{{item.obillId}}</td>
            <td colspan="3">初验时间: {{item.createTime.slice(0,11)}}</td>
            <td colspan="3">复验结束时间: {{item.createTime.slice(0,11)}}</td>
          </tr>
          <tr class="miui-table-content">
            <td colspan="3">
              <el-button type="text" @click="checkOptometryInfo(item)">{{item.billId}}</el-button>
            </td>
            <td>{{item.deptName}}</td>
            <td>{{item.optUserName}}</td>
            <td>初验</td>
            <td colspan="2">{{item.createTime.slice(0,11)}}</td>
            <td colspan="3">正式提交</td>
          </tr>
        </table>
      </div>
      <div class="avue-crud__pagination" v-if="list.length">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next"></el-pagination>
      </div>

      <!-- 弹窗，初验 -->
      <check-first v-if="checkFirstVisible" ref="checkFirstDialog"></check-first>
    </basic-container>
  </div>
</template>

<script>
  import { getCaseInfoPage } from "@/api/eims/customer";
  import { mapGetters } from "vuex";

  import CheckFirst from './components/CheckFirst'

  export default {
    props: ['customerData'],
    data() {
      return {
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        checkFirstVisible: false,
        list: [], //  病例列表--自己修改
      };
    },
    components: {
      CheckFirst
    },
    computed: {
      ...mapGetters(["permissions"])
    },
    methods: {
      // 初始化数据
      init(id,customerCard) {
        this.customerId = id
        this.customerCard = customerCard
        this.$nextTick(() => {
          this.getDataList()
        })
      },
      // 获取数据列表
      getDataList() {
        // this.dataListLoading = true;
        let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }
        let params2 = {
          customerId : this.customerId,
          customerCard: this.customerCard
        }
        getCaseInfoPage(Object.assign(params1, params2)).then(response => {
          if(response.data.code == '0'){
            this.list = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        });
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      saleTypeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case "1":
            return '隐形订做'
            break
          case "2":
            return '框镜订做'
            break
          case "3":
            return '隐形成品'
            break
          case "4":
            return '框镜成品'
            break
          case "5":
            return '辅料'
            break
        }
      },
      checkFlagFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case "1":
            return '内方'
            break
          case "0":
            return '辅料'
            break
        }
      },
      refundFlagFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case "1":
            return '已退货'
            break
          case "0":
            return '未退货'
            break
        }
      },
      // 打开验光单详情
      checkOptometryInfo(data){
        let checkData = {
          checkNumber: data.billId,
          checker: data.optUserId,
          checkerName: data.optUserName,
          checkDate: data.createTime
        }
        let customer = this.customerData
        let data1 = {
          type: 'first',
          billId: data.billId,
          checkData: checkData,
          customer: customer
        }
        this.checkFirstVisible = true
        this.$nextTick(() => {
          this.$refs.checkFirstDialog.init(data1)
        })
      }
    }
  };
</script>
<style lang="scss" scoped>
  .miui-table {
    width: 100%;

    th td,
    tr td {
      border: solid 1px #fff;
      padding: 5px 10px;
      width: 150px;
      text-align: center;
    }

    .miui-table-header {
      background-color: #7898a8;
      color: #fff;
    }

    .miui-table-content {
      background-color: #cadee8;
    }
  }
</style>
